package day07;

import java.util.Scanner;
import java.util.Arrays;
public class Exercise {
    public static void main(String[] args) {
        // 1. * 猜数字小游戏
        //    * 训练目标: while(true)自造死循环
        /*
        Scanner scan = new Scanner(System.in);
        int num = (int)(Math.random()*1000);
        System.out.println(num);
        while (true){
            System.out.println("猜吧");
            int guess = scan.nextInt();
            if(guess>num){
                System.out.println("猜大了");
            }else if (guess<num){
                System.out.println("猜小了");
            }else{
                System.out.println("猜对了");
                break;
            }
        }

         */
        // 2. * 需求:生成?位验证码(大写字母、小写字母、数字)
        /*
        String code = verifcationcode(8);
        System.out.println("验证码为"+code);

         */

        //3.   * 需求:----------常见面试题
        //    *   找到2到100之间的所有素数(质数)
        //    *   素数:除了1和它本身外，不能被其它任何自然数整数的数
        /*
        System.out.println("素数有：");
        for(int i=2;i<=100;i++){
            boolean flag =true;
            for (int j=2;j<=i/2;j++){
                if (i%j == 0){
                    flag = false;
                    break;
                }
            }
            if(flag){
                System.out.print(i+"\t");
            }
        }

         */

        // 需求：
        //     机票价格按照淡季旺季、头等舱、商务舱和经济舱收费，
        //     输入机票原价、月份和头等舱、商务舱或经济舱，
        //     其中旺季（5-10月）头等舱9折，商务舱85折，经济舱8折，
        //     淡季（11月到来年4月）头等舱7折，商务舱65折，经济舱6折，
        //     最终输出机票价格
            /*
        while (true) {
            Scanner scan = new Scanner(System.in);
            System.out.println("请输入机票原价：");
            double price = scan.nextDouble();
            if (price <= 0) {
                System.out.println("输入有误");
                continue;
            }
            System.out.println("请输入月份：");
            int month = scan.nextInt();
            if (month < 1 || month > 12) {
                System.out.println("输入有误");
                continue;
            }
            System.out.println("请按指令选择舱位：1.头等舱 2.商务舱 3.经济舱");
            int command = scan.nextInt();
            if (command>3||command<1){
                System.out.println("输入有误");
                continue;
            }
            double finalprice = finalprice(price,month,command);
            System.out.println("机票价格为：" + finalprice + "元");
            break;
        }

             */

        //5. * 需求:
        //    * <<主持人大赛>>有6名评委给选手打分，要求分数范围为0到100之间的整数。
        //    * 选手的最后得分为：去掉最高分、最低分后的4个评委的平均分
    /*
        System.out.println("选手的平均分为"+avg(6));
    }

     */
        /*
        Scanner scan = new Scanner(System.in);
        int result = (int)(Math.random()*1000+1);
        System.out.println(result);

        while (true){
            System.out.println("猜吧！");
            int guess = scan.nextInt();
            if(guess>result){
                System.out.println("猜大了");
            }else if(guess<result){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜你，猜对了");
                break;
            }
        }
        /*
        String code = generateVeriCode(4);
        System.out.println("验证码为："+code);
    }
     /*
        System.out.println("素数有：");
        for(int num = 2;num<=1000;num++){
        boolean flag = true;
        for(int i=2;i<=num/2;i++){
            if(num%i==0){
                flag = false;
                break;
            }
        }
        if(flag){
            System.out.print(num+"\t");
            }
        }

         */



        /*
        if(month>=1 && month <=12){
            if(month>=5 && month <=10){
                switch (command){
                    case 1:
                        System.out.println("机票价格为"+price*0.9);
                        break;
                    case 2:
                        System.out.println("机票价格为"+price*0.85);
                        break;
                    case 3:
                        System.out.println("机票价格为"+price*0.8);
                        break;
                    default:
                        System.out.println("信息输入有误");
                }
            }else if(month<=4 && month >=10){
                switch (command){
                    case 1:
                        System.out.println("机票价格为"+price*0.7);
                        break;
                    case 2:
                        System.out.println("机票价格为"+price*0.65);
                        break;
                    case 3:
                        System.out.println("机票价格为"+price*0.6);
                        break;
                    default:
                        System.out.println("信息输入有误");
                }
            }
        }else{
            System.out.println("信息输入有误");
        }

         */

       /*
        double[] scores = EnterDate();
        double total = Totalscores(scores);
        System.out.println("总分为"+total+"分");
        double avg = Avgscores(scores);
        System.out.println("平均分为"+avg+"分");

        */
    }

    /*
    public static String verifcationcode(int len){
        String code = "";
        char[] chs ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                '0','1','2','3','4','5','6','7','8','9'};
        for(int i=0;i<len;i++){
            code += chs[(int) (Math.random()* chs.length)];
        }
        return code;

    }

     */
    /*
    public static double finalprice(double price,int month,int command){
            double finalprice =0.0;
            if (month>=5 &&month<=10){
                switch (command){
                    case 1:
                        finalprice = price *0.9;
                        break;
                    case 2:
                        finalprice = price *0.85;
                        break;
                    case 3:
                        finalprice = price*0.8;
                        break;
                }
            }else {
                switch (command){
                    case 1:
                        finalprice = price *0.7;
                        break;
                    case 2:
                        finalprice = price *0.65;
                        break;
                    case 3:
                        finalprice = price*0.6;
                        break;
                }
            }
                return finalprice;
    }

     */

        /*
        public static double[] scores(int len){
            Scanner scan= new Scanner(System.in);
            double[] scores = new double[len];
            for (int i=0;i< scores.length;i++) {
                System.out.println("请输入第"+(i+1)+"个评委的打分：");
                double score = scan.nextDouble();
                scores[i] = score;
            }
            return scores;
        }

        public static double avg(int len){
            double[] arr = scores(len);
            double total = 0.0;
            double max = arr[0];
            double min = arr[0];
            for (int i=0;i< arr.length;i++){
                total += arr[i];
                if(max<arr[i]){
                    max = arr[i];
                }else if(min>arr[i]){
                    min = arr[i];
                }
            }

            double avg = (total-max-min)/(len-2);
            return avg;

        }

         */
    /*
        public static String generateVeriCode(int len){
            String code = "";
            //……
            char[] chs = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                    '0','1','2','3','4','5','6','7','8','9'};

            for(int i=0;i<len;i++){
                code += chs[(int) (Math.random()* chs.length)];
            }
            return code;
        }

     */
    /*
        public static double[] EnterDate() {
            Scanner scan = new Scanner(System.in);
            double[] scores = new double[6];
            for (int i = 0; i < scores.length; i++) {
                System.out.println("请输入第" + (i + 1) + "个评委的成绩");
                scores[i] = scan.nextDouble();
            }
            return scores;
        }

    public static double Totalscores(double[] scores){

        double Total = 0.0;
        for (int i = 0; i < scores.length; i++){
            Total += scores[i];
        }

        return Total;
    }

    public static double Avgscores(double[] scores){
        double Total = 0.0;
        Arrays.sort(scores);
        for (int i = 1; i < scores.length-1; i++){
            Total += scores[i];
        }
        double avg = Total/(scores.length-2);

        return avg;
    }

     */
}

